package com.education.module.teacherExamSetting;

import com.education.domain.*;
import com.education.framework.base.BaseServices;
import com.education.framework.dao.IDao;
import com.education.framework.domain.SearchParams;
import com.education.framework.page.Page;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherExamSettingServices extends BaseServices implements IDao<TeacherExamSetting>{

	@Override
	public List<TeacherExamSetting> find(SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT distinct s.code,s.name,s.content,s.exam_date_id,d.startDate,d.endDate,d.description FROM teacher_exam_setting s left join examDate d on s.exam_date_id = d.id");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" s.name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
		}
		sql.append(" order by s.id ");
		Object[] args = argsList.toArray();
		List<TeacherExamSetting> list = dao.query(pageSQL(sql.toString(),page),args,new TeacherExamSettingRowmapper());
		page.setTotalItem(findRecordCount("select count(DISTINCT code) as cNum from teacher_exam_setting ",new Object[]{}));
		return list;
	}
	
	public List<TeacherExamSetting> find() {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id,code,teacher_id,exam_date_id FROM teacher_exam_setting");
		
		List<TeacherExamSetting> list = dao.query(sql.toString(),new TeacherExamSettingRowmapper());
		return list;
	}

	public List<TeacherExamSetting2> findExamSystem2ByCode(int code) {
		StringBuffer sql = new StringBuffer();
		sql.append("(SELECT code,name,content,teacher_id,exam_date_id,kind_id,weight FROM teacher_exam_setting_2 where code="+code+") union ");
		sql.append("(SELECT code,name,content,teacher_id,exam_date_id,'','' FROM teacher_exam_setting where code="+code+" and teacher_id not in (select teacher_id from teacher_exam_setting_2 where code= "+code+")) ");
		sql.append("order by teacher_id,kind_id");
		List<TeacherExamSetting2> list = dao.query(sql.toString(),new TeacherExamSetting2CodeRowmapper());
		return list;
	}

	public List<TeacherExamSetting3> findExamSystem3ByCode(int code) {
		StringBuffer sql = new StringBuffer();
		sql.append("select DISTINCT code,name,content,exam_date_id,teacher_id,kind_id,weight,exam_item_id,score from teacher_exam_setting_3 where code = "+code);

		List<TeacherExamSetting3> list = dao.query(sql.toString(),new TeacherExamSetting3CodeRowmapper());
		return list;
	}

	public List<Kind> findKindForSelect(int code,int teacherId,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select k.id,k.kind_name,k.remark from kind k where k.id not in (SELECT t.kind_id from teacher_exam_setting_2 t where t.code = "+code+" and t.teacher_id = "+teacherId+")");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" k.kind_name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
		}
		Object[] args = argsList.toArray();
		List<Kind> list = dao.query(pageSQL(sql.toString(),page),args,new KindRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from kind ",new Object[]{}));
		return list;
	}

	public List<TeacherExamSetting2> findSelectedKind(int code, int teacherId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT code,name,content,teacher_id,exam_date_id,kind_id,weight FROM teacher_exam_setting_2 where code="+code+" and teacher_id="+teacherId);

		List<TeacherExamSetting2> list = dao.query(sql.toString(),new TeacherExamSetting2CodeRowmapper());
		return list;
	}

	public List<Examdate> findExamdates() {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id,code,startdate,enddate,description FROM examDate");

		List<Examdate> list = dao.query(sql.toString(),new ExamdateRowmapper());
		return list;
	}

	public List<TeacherExamSetting> findByCode(int code) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT code,name,content,teacher_id,exam_date_id FROM teacher_exam_setting where code = "+code+" order by teacher_id");

		List<TeacherExamSetting> list = dao.query(sql.toString(),new TeacherExamSettingCodeRowmapper());
		return list;
	}

	public int findCountByCode(int code) {
		return findRecordCount("SELECT count(*) from teacher_exam_setting where code = "+code,new Object[]{});
	}

	public List<Teacher> findTeachersForSelect(String ids,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.teacher_name,t.remark,t.professional_id,p.pro_name FROM teacher t left join professional p on t.professional_id = p.id");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.teacher_name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
		}
		if (ids != null && !"".equals(ids)){
			sql.append(lp).append(" t.id not in ("+ids+") ");
			lp = " and ";
		}
		Object[] args = argsList.toArray();
		List<Teacher> list = dao.query(pageSQL(sql.toString(),page),args,new TeacherRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from teacher ",new Object[]{}));
		return list;
	}

	public List<Teacher> findTeachers(String ids,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.teacher_name,t.remark,t.professional_id,p.pro_name FROM teacher t left join professional p on t.professional_id = p.id");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.teacher_name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
		}
		if (ids != null && !"".equals(ids)){
			sql.append(lp).append(" t.id in ("+ids+") ");
			lp = " and ";
		}
		Object[] args = argsList.toArray();
		List<Teacher> list = dao.query(pageSQL(sql.toString(),page),args,new TeacherRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from teacher ",new Object[]{}));
		return list;
	}

	public List<Student> findStudentsForSystem(int code,int teacherId,int kindId,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.truename,t.grade_id,t.class_id,t.professional_id FROM student t");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.truename like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("loginname") && !"".equals((String)searchParams.get("loginname"))){
				sql.append(lp).append(" t.loginname like ? ");
				argsList.add("%" + searchParams.get("loginname") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("gradeId") && !"".equals((String)searchParams.get("gradeId"))){
				sql.append(lp).append(" t.grade_id = ? ");
				argsList.add(searchParams.get("gradeId"));
				lp = " and ";
			}
			if(null != searchParams.get("classId") && !"".equals((String)searchParams.get("classId"))){
				sql.append(lp).append(" t.class_id = ? ");
				argsList.add(searchParams.get("classId"));
				lp = " and ";
			}
			if(null != searchParams.get("professionalId") && !"".equals((String)searchParams.get("professionalId"))){
				sql.append(lp).append(" t.professional_id = ? ");
				argsList.add(searchParams.get("professionalId"));
				lp = " and ";
			}
		}
		sql.append(lp).append(" t.id in (select r.user_id from teacher_exam_result r where r.code=" + code + " and r.teacher_id=" + teacherId + " and r.kind_id=" + kindId + " and r.user_type=2)");
		Object[] args = argsList.toArray();
		List<Student> list = dao.query(pageSQL(sql.toString(),page),args,new StudentRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from student ",new Object[]{}));
		return list;
	}

	public List<Student> selectStudentsForSystem(int code,int teacherId,int kindId,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.truename,t.grade_id,t.class_id,t.professional_id FROM student t");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.truename like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("loginname") && !"".equals((String)searchParams.get("loginname"))){
				sql.append(lp).append(" t.loginname like ? ");
				argsList.add("%" + searchParams.get("loginname") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("gradeId") && !"".equals((String)searchParams.get("gradeId"))){
				sql.append(lp).append(" t.grade_id = ? ");
				argsList.add(searchParams.get("gradeId"));
				lp = " and ";
			}
			if(null != searchParams.get("classId") && !"".equals((String)searchParams.get("classId"))){
				sql.append(lp).append(" t.class_id = ? ");
				argsList.add(searchParams.get("classId"));
				lp = " and ";
			}
			if(null != searchParams.get("professionalId") && !"".equals((String)searchParams.get("professionalId"))){
				sql.append(lp).append(" t.professional_id = ? ");
				argsList.add(searchParams.get("professionalId"));
				lp = " and ";
			}
		}
		sql.append(lp).append(" t.id not in (select r.user_id from teacher_exam_result r where r.code=" + code + " and r.teacher_id=" + teacherId + " and r.kind_id=" + kindId + " and r.user_type=2)");
		Object[] args = argsList.toArray();
		List<Student> list = dao.query(pageSQL(sql.toString(),page),args,new StudentRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from student ",new Object[]{}));
		return list;
	}

	public List<Teacher> findTeachersForSystem(int code,int teacherId,int kindId,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.teacher_name,t.professional_id,t.type_id FROM teacher t");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.teacher_name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("loginname") && !"".equals((String)searchParams.get("loginname"))){
				sql.append(lp).append(" t.loginname like ? ");
				argsList.add("%" + searchParams.get("loginname") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("typeId") && !"".equals((String)searchParams.get("typeId"))){
				sql.append(lp).append(" t.type_id = ? ");
				argsList.add(searchParams.get("typeId"));
				lp = " and ";
			}
			if(null != searchParams.get("professionalId") && !"".equals((String)searchParams.get("professionalId"))){
				sql.append(lp).append(" t.professional_id = ? ");
				argsList.add(searchParams.get("professionalId"));
				lp = " and ";
			}
		}
		sql.append(lp).append(" t.id in (select r.user_id from teacher_exam_result r where r.code=" + code + " and r.teacher_id=" + teacherId + " and r.kind_id=" + kindId + " and r.user_type=1)");
		Object[] args = argsList.toArray();
		List<Teacher> list = dao.query(pageSQL(sql.toString(),page),args,new TeacherSystemRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from teacher ",new Object[]{}));
		return list;
	}

	public List<Teacher> selectTeachersForSystem(int code,int teacherId,int kindId,SearchParams searchParams, Page page) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id,t.teacher_name,t.professional_id,t.type_id FROM teacher t");
		String lp = " where ";
		List<Object> argsList = new ArrayList<Object>();
		if(null != searchParams){
			if(null != searchParams.get("name") && !"".equals((String)searchParams.get("name"))){
				sql.append(lp).append(" t.teacher_name like ? ");
				argsList.add("%" + searchParams.get("name") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("loginname") && !"".equals((String)searchParams.get("loginname"))){
				sql.append(lp).append(" t.loginname like ? ");
				argsList.add("%" + searchParams.get("loginname") + "%");
				lp = " and ";
			}
			if(null != searchParams.get("typeId") && !"".equals((String)searchParams.get("typeId"))){
				sql.append(lp).append(" t.type_id = ? ");
				argsList.add(searchParams.get("typeId"));
				lp = " and ";
			}
			if(null != searchParams.get("professionalId") && !"".equals((String)searchParams.get("professionalId"))){
				sql.append(lp).append(" t.professional_id = ? ");
				argsList.add(searchParams.get("professionalId"));
				lp = " and ";
			}
		}
		sql.append(lp).append(" t.id not in (select r.user_id from teacher_exam_result r where r.code=" + code + " and r.teacher_id=" + teacherId + " and r.kind_id=" + kindId + " and r.user_type=1)");
		Object[] args = argsList.toArray();
		List<Teacher> list = dao.query(pageSQL(sql.toString(),page),args,new TeacherSystemRowmapper());
		page.setTotalItem(findRecordCount("select count(id) as cNum from teacher ",new Object[]{}));
		return list;
	}

	@Override
	public int save(TeacherExamSetting obj) {
		 
		 StringBuffer sql = new StringBuffer();
		 sql.append("insert into teacher_exam_setting ( ");
		 sql.append("code,name,content,teacher_id,exam_date_id ");
		 sql.append(" ) values(?,?,?,?,?) ");
		 Object[] args = {obj.getCode(),obj.getName(),obj.getContent(),obj.getTeacherId(),obj.getExamDateId() };

		 dao.update(sql.toString(), args);
		return dao.queryForInt("SELECT LAST_INSERT_ID()"); 
	}

	public int saveKind(int code, int teacherId, String kindId) {

		StringBuffer sql = new StringBuffer();
		sql.append("insert into teacher_exam_setting_2 ( ");
		sql.append("code,name,content,teacher_id,exam_date_id,kind_id,weight ");
		sql.append(" ) select code,name,content,teacher_id,exam_date_id,"+kindId+",0 from teacher_exam_setting where code="+code+" and teacher_id="+teacherId);
		Object[] args = { };

		dao.update(sql.toString(), args);
		return dao.queryForInt("SELECT LAST_INSERT_ID()");
	}

	public void saveUserForResult(int code, int teacherId, int kindId, String userIds, int userType) {

		String[] userIdArrs ;
		if (userIds != null && !"".equals(userIds)) {
			userIdArrs = userIds.split(",");
			for (String userId : userIdArrs) {
				StringBuffer sql = new StringBuffer();
				sql.append("insert into teacher_exam_result ( ");
				sql.append("code,name,content,teacher_id,exam_date_id,kind_id,weight,exam_item_id,user_id,user_type,score,state ");
				sql.append(" ) select code,name,content,teacher_id,exam_date_id,kind_id,weight,exam_item_id," + userId + "," + userType + ",score,0 from teacher_exam_setting_3 where code=" + code + " and teacher_id=" + teacherId + " and kind_id=" + kindId);
				Object[] args = {};
				dao.update(sql.toString(), args);
			}
		}
	}

	public void copyStepThirdDatas(int code, int teacherId, String kindId) {

		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id FROM exam_item where kind_id ="+kindId+" order by id");
		List<ExamItem> list = dao.query(sql.toString(),new ExamItemRowmapper());

		if (list != null && list.size() > 0){
			for (ExamItem examItem : list) {
				sql = new StringBuffer();
				sql.append("insert into teacher_exam_setting_3 ( ");
				sql.append("code,name,content,teacher_id,exam_date_id,kind_id,weight,exam_item_id ");
				sql.append(" ) select code,name,content,teacher_id,exam_date_id,kind_id,weight,"+examItem.getId()+" from teacher_exam_setting_2 where code="+code+" and teacher_id="+teacherId+" and kind_id ="+kindId);
				Object[] args = { };
				dao.update(sql.toString(), args);
			}
		}
	}

	@Override
	public TeacherExamSetting findForObject(Integer id) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id,code,teacher_id,exam_date_id FROM teacher_exam_setting ");
		sql.append(" where id=? ");
		
		Object[] args = {id};
		return dao.queryForObject(sql.toString(),args,new TeacherExamSettingRowmapper());
	}

	@Override
	public void update(TeacherExamSetting obj) {
		 
		 StringBuffer sql = new StringBuffer();
		 sql.append("update teacher_exam_setting ");
		 sql.append("set  ");
		 sql.append("name=?,content=?,exam_date_id=? where code=?  ");
		 Object[] args = {obj.getName(),obj.getContent(),obj.getExamDateId(),obj.getCode() };
		 
		 dao.update(sql.toString(), args);
	}

	public void updateAllSystemData(TeacherExamSetting obj) {

		StringBuffer sql = new StringBuffer();
		sql.append("update teacher_exam_setting_2 ");
		sql.append("set  ");
		sql.append("name=?,content=? where code=?  ");
		Object[] args = {obj.getName(),obj.getContent(),obj.getCode() };
		dao.update(sql.toString(), args);

		sql = new StringBuffer();
		sql.append("update teacher_exam_setting_3 ");
		sql.append("set  ");
		sql.append("name=?,content=? where code=?  ");
		Object[] args2 = {obj.getName(),obj.getContent(),obj.getCode() };
		dao.update(sql.toString(), args);

		sql = new StringBuffer();
		sql.append("update teacher_exam_result ");
		sql.append("set  ");
		sql.append("name=?,content=? where code=?  ");
		Object[] args3 = {obj.getName(),obj.getContent(),obj.getCode() };
		dao.update(sql.toString(), args);
	}

	public void updateThirdStep(String[] weightIdArrs,String[] weightArrs,String[] itemScoreIdArrs,String[] scoreArrs) {

		if (weightIdArrs != null && weightIdArrs.length > 0){
			String tempId = weightIdArrs[0];
			for (int i = 0 ;i < weightIdArrs.length; i++){
				if (i == 0){
					String[] weightParams = weightIdArrs[i].split("@");
					StringBuffer sql = new StringBuffer();
					sql.append("update teacher_exam_setting_3 ");
					sql.append("set  ");
					sql.append("weight=? where code=? and teacher_id = ? and kind_id = ? ");
					Object[] args = {weightArrs[i], weightParams[0], weightParams[1], weightParams[2]};
					dao.update(sql.toString(), args);
					sql = new StringBuffer();
					sql.append("update teacher_exam_result ");
					sql.append("set  ");
					sql.append("weight=? where code=? and teacher_id = ? and kind_id = ? ");
					Object[] args1 = {weightArrs[i], weightParams[0], weightParams[1], weightParams[2]};
					dao.update(sql.toString(), args);
				}else if (!tempId.equals(weightIdArrs[i])) {
					tempId = weightIdArrs[i];
					String[] weightParams = weightIdArrs[i].split("@");
					StringBuffer sql = new StringBuffer();
					sql.append("update teacher_exam_setting_3 ");
					sql.append("set  ");
					sql.append("weight=? where code=? and teacher_id = ? and kind_id = ? ");
					Object[] args = {weightArrs[i], weightParams[0], weightParams[1], weightParams[2]};
					dao.update(sql.toString(), args);
					sql = new StringBuffer();
					sql.append("update teacher_exam_result ");
					sql.append("set  ");
					sql.append("weight=? where code=? and teacher_id = ? and kind_id = ? ");
					Object[] args1 = {weightArrs[i], weightParams[0], weightParams[1], weightParams[2]};
					dao.update(sql.toString(), args);
				}
			}
		}

		if (itemScoreIdArrs != null && itemScoreIdArrs.length > 0){
			for (int i = 0 ;i < itemScoreIdArrs.length; i++){
				String[] itemParams = itemScoreIdArrs[i].split("@");
				StringBuffer sql = new StringBuffer();
				sql.append("update teacher_exam_setting_3 ");
				sql.append("set  ");
				sql.append("score=? where code=? and teacher_id = ? and kind_id = ? and exam_item_id = ? ");
				Object[] args = {scoreArrs[i],itemParams[0],itemParams[1],itemParams[2],itemParams[3] };
				dao.update(sql.toString(), args);
				sql = new StringBuffer();
				sql.append("update teacher_exam_result ");
				sql.append("set  ");
				sql.append("score=? where code=? and teacher_id = ? and kind_id = ? and exam_item_id = ? ");
				Object[] args1 = {scoreArrs[i],itemParams[0],itemParams[1],itemParams[2],itemParams[3] };
				dao.update(sql.toString(), args);
			}
		}
	}

	@Override
	public void delete(Integer code) {
		String sql = "delete from teacher_exam_setting where code=?";
		dao.update(sql, new Object[]{code});
	}

	public void deleteTeacher(Integer id,Integer code) {
		String sql = "delete from teacher_exam_setting where teacher_id=? and code = ?";
		dao.update(sql, new Object[]{id,code});
		sql = "delete from teacher_exam_setting_2 where teacher_id=? and code = ?";
		dao.update(sql, new Object[]{id,code});
		sql = "delete from teacher_exam_setting_3 where teacher_id=? and code = ?";
		dao.update(sql, new Object[]{id,code});
		sql = "delete from teacher_exam_result where teacher_id=? and code = ?";
		dao.update(sql, new Object[]{id,code});
	}

	public void deleteKind(Integer id,Integer code,Integer teacherId) {
		String sql = "delete from teacher_exam_setting_2 where teacher_id=? and code = ? and kind_id = ?";
		dao.update(sql, new Object[]{teacherId,code,id});
		sql = "delete from teacher_exam_setting_3 where teacher_id=? and code = ? and kind_id = ?";
		dao.update(sql, new Object[]{teacherId,code,id});
		sql = "delete from teacher_exam_result where teacher_id=? and code = ? and kind_id = ?";
		dao.update(sql, new Object[]{teacherId,code,id});
	}

	public void deleteUser(Integer id,Integer code,Integer teacherId,Integer kindId,Integer userType) {
		String sql = "delete from teacher_exam_result where user_id=? and code = ? and teacher_id=? and kind_id = ? and user_type = ?";
		dao.update(sql, new Object[]{id,code,teacherId,kindId,userType});
	}

	public int checkHasScore(int code) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT count(*) FROM teacher_exam_result where code=? and state = 1 ");
		Object[] args = {code};
		return dao.queryForInt(sql.toString(),args);
	}

	@Override
	public boolean findIsExist(String name) {
		return false;
	}
	
	private class TeacherExamSettingRowmapper implements RowMapper<TeacherExamSetting> {
		@Override
		public TeacherExamSetting mapRow(ResultSet rs, int arg1) throws SQLException {
			TeacherExamSetting obj = new TeacherExamSetting();
			obj.setName(rs.getString("name"));
			obj.setContent(rs.getString("content"));
			obj.setCode(rs.getInt("code"));
			obj.setExamDateId(rs.getInt("exam_date_id"));
			Examdate examdate = new Examdate();
			examdate.setId(rs.getInt("exam_date_id"));
			examdate.setStartdate(rs.getString("startDate"));
			examdate.setEnddate(rs.getString("endDate"));
			examdate.setDescription(rs.getString("description"));
			obj.setExamDate(examdate);
			return obj;
		}
	}

	private class TeacherRowmapper implements RowMapper<Teacher> {
		@Override
		public Teacher mapRow(ResultSet rs, int arg1) throws SQLException {
			Teacher obj = new Teacher();
			obj.setId(rs.getInt("id"));
			obj.setTeacherName(rs.getString("teacher_name"));
			obj.setRemark(rs.getString("remark"));
			Professional professional = new Professional();
			professional.setId(rs.getInt("professional_id"));
			professional.setProName(rs.getString("pro_name"));
			obj.setProfessional(professional);
			return obj;
		}
	}

	private class TeacherSystemRowmapper implements RowMapper<Teacher> {
		@Override
		public Teacher mapRow(ResultSet rs, int arg1) throws SQLException {
			Teacher obj = new Teacher();
			obj.setId(rs.getInt("id"));
			obj.setTeacherName(rs.getString("teacher_name"));
			obj.setProfessionalId(rs.getInt("professional_id"));
			obj.setTypeId(rs.getInt("type_id"));
			return obj;
		}
	}

	private class ExamdateRowmapper implements RowMapper<Examdate> {
		@Override
		public Examdate mapRow(ResultSet rs, int arg1) throws SQLException {
			Examdate obj = new Examdate();
			obj.setId(rs.getInt("id"));
			obj.setCode(rs.getString("code"));
			obj.setStartdate(rs.getString("startDate"));
			obj.setEnddate(rs.getString("endDate"));
			obj.setDescription(rs.getString("description"));
			return obj;
		}
	}

	private class KindRowmapper implements RowMapper<Kind> {
		@Override
		public Kind mapRow(ResultSet rs, int arg1) throws SQLException {
			Kind obj = new Kind();
			obj.setId(rs.getInt("id"));
			obj.setKindName(rs.getString("kind_name"));
			obj.setRemark(rs.getString("remark"));
			return obj;
		}
	}

	private class ExamItemRowmapper implements RowMapper<ExamItem> {
		@Override
		public ExamItem mapRow(ResultSet rs, int arg1) throws SQLException {
			ExamItem obj = new ExamItem();
			obj.setId(rs.getInt("id"));
			return obj;
		}
	}

	private class TeacherExamSettingCodeRowmapper implements RowMapper<TeacherExamSetting> {
		@Override
		public TeacherExamSetting mapRow(ResultSet rs, int arg1) throws SQLException {
			TeacherExamSetting obj = new TeacherExamSetting();
			obj.setName(rs.getString("name"));
			obj.setContent(rs.getString("content"));
			obj.setCode(rs.getInt("code"));
			obj.setTeacherId(rs.getString("teacher_id"));
			obj.setExamDateId(rs.getInt("exam_date_id"));
			return obj;
		}
	}

	private class StudentRowmapper implements RowMapper<Student> {
		@Override
		public Student mapRow(ResultSet rs, int arg1) throws SQLException {
			Student obj = new Student();
			obj.setId(rs.getInt("id"));
			obj.setTruename(rs.getString("truename"));
			obj.setGradeId(rs.getInt("grade_id"));
			obj.setClassId(rs.getInt("class_id"));
			obj.setProfessionalId(rs.getInt("professional_id"));
			return obj;
		}
	}

	private class TeacherExamSetting2CodeRowmapper implements RowMapper<TeacherExamSetting2> {
		@Override
		public TeacherExamSetting2 mapRow(ResultSet rs, int arg1) throws SQLException {
			TeacherExamSetting2 obj = new TeacherExamSetting2();
			obj.setName(rs.getString("name"));
			obj.setContent(rs.getString("content"));
			obj.setCode(rs.getInt("code"));
			obj.setTeacherId(rs.getString("teacher_id"));
			obj.setExamDateId(rs.getInt("exam_date_id"));
			obj.setKindId(rs.getString("kind_id"));
			obj.setWeight(rs.getString("weight"));
			return obj;
		}
	}

	private class TeacherExamSetting3CodeRowmapper implements RowMapper<TeacherExamSetting3> {
		@Override
		public TeacherExamSetting3 mapRow(ResultSet rs, int arg1) throws SQLException {
			TeacherExamSetting3 obj = new TeacherExamSetting3();
			obj.setName(rs.getString("name"));
			obj.setContent(rs.getString("content"));
			obj.setCode(rs.getInt("code"));
			obj.setTeacherId(rs.getString("teacher_id"));
			obj.setExamDateId(rs.getInt("exam_date_id"));
			obj.setKindId(rs.getString("kind_id"));
			obj.setWeight(rs.getString("weight"));
			obj.setExamItemId(rs.getString("exam_item_id"));
			obj.setScore(rs.getString("score"));
			return obj;
		}
	}


}
